using UnityEngine;

public class CourtStateFoul : AbstractCourtState
{
	public static CourtStateFoul instance;

	private CourtStateFoul()
	{
	}

	public static CourtStateFoul getInstance()
	{
		if (instance == null)
		{
			instance = new CourtStateFoul();
		}
		return instance;
	}

	public override void enter(Court owner)
	{
		base.enter(owner);
		Instance<Referee>.instance.do_whistle();
		Player player = null;
		if (owner.teamUser.IsAnyOneControlBall())
		{
			player = owner.teamUser.getPlayer_ControlBall();
			player.do_idle();
		}
		else if (owner.teamComputer.IsAnyOneControlBall())
		{
			player = owner.teamComputer.getPlayer_ControlBall();
			player.AI.do_idle();
		}
		switch (owner.foulType)
		{
		case FoulType.BACKCOURT:
			Instance<Ball>.instance.setVelocityZero();
			Instance<Ball>.instance.do_idle();
			owner.do_baseline((owner.foulTeamType != TeamType.COMPUTER) ? TeamType.COMPUTER : TeamType.USER, Global.posSideLine[Random.Range(0, 2)]);
			break;
		case FoulType.CHARGING:
			Instance<Ball>.instance.setVelocityZero();
			Instance<Ball>.instance.do_idle();
			owner.do_baseline((owner.foulTeamType != TeamType.COMPUTER) ? TeamType.COMPUTER : TeamType.USER, Global.posSideLine[Random.Range(0, 2)]);
			break;
		case FoulType.STEAL:
			Instance<Ball>.instance.setVelocityZero();
			Instance<Ball>.instance.do_idle();
			if (player != null)
			{
				if (player.teamType == TeamType.USER)
				{
					player.do_tumble();
				}
				else
				{
					player.AI.do_tumble();
				}
				player.playAnimation(AnimationName.player_tumble_charging, 1f, 0.8f);
			}
			owner.do_baseline((owner.foulTeamType != TeamType.COMPUTER) ? TeamType.COMPUTER : TeamType.USER, Global.posSideLine[Random.Range(0, 2)]);
			break;
		case FoulType.BLOCK:
			Instance<Ball>.instance.getBallOutHand();
			owner.do_freethrow();
			break;
		case FoulType.OUTSIDE:
			Instance<Ball>.instance.setVelocityZero();
			Instance<Ball>.instance.do_idle();
			owner.do_baseline((owner.foulTeamType != TeamType.COMPUTER) ? TeamType.COMPUTER : TeamType.USER, Instance<Ball>.instance.pos_Out);
			break;
		}
	}
}
